package demo03.SwingObserver;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
//观察者模式在Swing中应用
public class SwingObserverExample {
	JFrame jframe;
	public void go(){
		jframe = new JFrame();
		JButton button = new JButton("我该如何选择");
		// Without lambdas
		button.addActionListener(new angelListener());//监听
		button.addActionListener(new DevilListener());
		// With lambdas   java 8  lambda表达式
	/*			button.addActionListener(event -> 
					System.out.println("Don't do it, you might regret it!")
				);
				button.addActionListener(event ->
					System.out.println("Come on, do it!")
				);*/
		
		jframe.getContentPane().add(BorderLayout.CENTER, button);//按钮添加都组件
		jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//jframe.getContentPane().add(BorderLayout.CENTER, button);
		jframe.setSize(300,300);
		jframe.setVisible(true);
	}
 
	public static void main(String[] args) {
		SwingObserverExample example = new SwingObserverExample();
		example.go();
	}
}
